﻿#region 命名空间

using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Collections.Generic;
using WinnerCMS.Data;
using WinnerCMS.Common;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.BLL
{
    public class MemberAddressManage : MarshalByRefObject
    {
        private static readonly UserAddressDal Dal = new UserAddressDal();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        [Logging("添加/修改用户地址。"), ExceptionCall]
        public Result Add(UserAddress model)
        {
            Result res = new Result();
            if (model.UserId == 0)
            {
                res.Errors = "用户名不能为空";
                return res;
            }
            if (model.Tel.Length == 0 && model.Moblie.Length == 0)
            {
                res.Errors = "手机和电话号码不能同时为空！";
                return res;
            }


            if (model.Id == 0)
            {
                Dal.Add(model);
            }
            else
            {
                Dal.Edit(model);
            }

            return res;
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        [Logging("删除用户地址。"), ExceptionCall]
        public Result Delete(int id)
        {
            Result res = new Result();
            Dal.Delete(id);
            return res;
        }

        #endregion

        #region 加载数据

        /// <summary>
        /// 加载数据
        /// </summary>
        public UserAddress SelectOne(string id)
        {
            return Dal.SelectByID(int.Parse(id));
        }

        #endregion

        public IList<UserAddress> SelectByUserName(string userName)
        {
            return Dal.SelectByUserName(userName);
        }
    }
}